package com.service;

import com.model.Student;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class ExportService {
    public void exportGrades(List<Student> students, String filePath) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
            writer.write("Name,Score");
            writer.newLine(); // 添加一个新行，以便数据从下一行开始
            for (Student student : students) {
                writer.write(student.getName() + "," + student.getScore());
                writer.newLine(); // 每个学生记录后添加一个新行
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}